﻿
<!DOCTYPE html>
<html>
 <head> 
  <meta charset="utf-8" /> 
  <title>添加考试</title> 
  <meta name="renderer" content="webkit" /> 
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> 
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
  <!-- // 样式表单--> 
  <script src="../../../layui/src/layui.js"></script> 
  <link href="../../../layui/layui/css/layui.css" rel="stylesheet" /> 
  <!--上传--> 
  <script src="../../../js/js/jquery/jquery-1.10.2.min.js"></script> 
  <link href="../../../layui/layui/uploader.css" rel="stylesheet" /> 
  <script src="../../../layui/uploader/webuploader/webuploader.min.js"></script> 
  <script src="../../../layui/uploader/uploader.js"></script> 

  <style>
body{padding: 10px;}
</style> 
 </head> 
 <body  onload="getPageReload()"> 
      <form class="layui-form layui-form-pane1" action="" lay-filter="first" id ="exam-add"> 

     <!--// 选择学生-->
    <div class="layui-form-item"> 
    <label class="layui-form-label">选择学生</label> 
    <div class="layui-input-block" id="student-list"> 

    </div> 
   </div> 


  <!--// 选择测验-->
    <div class="layui-form-item"> 
    <label class="layui-form-label">选择测验</label> 
    <div class="layui-input-block" id="exam-file"> 

    </div> 
   </div> 

  <form class="layui-form layui-form-pane1" action="" lay-filter="first" id ="teacher-add"> 
   <div class="layui-form-item"> 
    <label class="layui-form-label">测验成绩</label> 
    <div class="layui-input-block"> 
     <input type="text" name="score" id="score" lay-verify="required|title" required="" placeholder="请输入测验成绩" autocomplete="off" class="layui-input" /> 
    </div> 
   </div> 


   <div class="layui-form-item"> 
    <div class="layui-inline"> 
     <label class="layui-form-label">上传内容</label> 
     <div class="layui-input-inline"> 
      <input type="text" name="upload" id="upload" autocomplete="off" class="layui-input upload-path" />
      <div class="upload-box upload-img"></div> 
     </div> 
    </div> 
   </div> 

     <div class="layui-form-item layui-form-text"> 
    <label class="layui-form-label">请填写描述</label> 
    <div class="layui-input-block"> 
     <textarea placeholder="请输入内容" class="layui-textarea" name="marks" id="marks"></textarea> 
    </div> 
   </div> 


   <div class="layui-form-item"> 
    <div class="layui-input-block"> 
     <button class="layui-btn" lay-submit="" lay-filter="*" onclick="addExamManager()">立即提交</button> 
 
    </div> 
   </div> 
  </form> 
  <script>
      $(function () {
          //初始化上传控件
          $(".upload-img").InitUploader({ filesize: "0", sendurl: "../ChireInter/Other/Upload/fileupload.ashx", swf: "../layui/uploader/webuploader/uploader.swf", filetypes: "jpg,jpeg,png,gif,bmp" });
      });

      function addExamManager() {

          // 1. 获取测验ID
          var exam = $('#exam-selected')

          var examId = "";
          var oContent1 = $('#exam-file')
          for (var i in oContent1.data("data")) {
              if (oContent1.data("data")[i].name == exam.val()) {
                  examId = oContent1.data("data")[i].id;
              }
          }
        
          // 2. 获取学生ID
          var studentSelected = $('#student-selected')

          var studentId = "";
          var oContent2 = $('#student-list')
          for (var i in oContent2.data("data")) {
              if (oContent2.data("data")[i].name == studentSelected.val()) {
                  studentId = oContent2.data("data")[i].id;
              }
          }
            
          // 3. 分数
          $score = $('#score').val();
          // 4. 添加file
          $file = $('#upload').val();
          // 5. 添加
          $marks = $('#marks').val();
   
          alert(examId + studentId);
          $.ajax({
              url: '../../../ChireInter/Exam/Exam_Add.ashx',
              data: { studentId: studentId,examId:examId,score:$score,fileUrl:$file,marks:$marks},
              type: 'post',
              dataType: 'json',
              success: function (res) {
                  if (res.errCode == 200) {
                      alert("提交成功");
                  } else {
                      alert('提交失败');
                  }
              },
              error: function (err) {
                  alert('提交失败' + err);
              }
          })

      }

      function getPageReload() {
          getExamFileListManager();
          getStudentsListManager();
      }

      //// 获取测验列表
      function getExamFileListManager() {
          $.ajax({
              url: '../../../ChireInter/Exam/Exam_File_List.ashx',
              data: { name: "sma" },
              type: 'post',
              dataType: 'json',
              success: function (res) {
                  if (res.errCode == 200) {
                      var html = "";

                      html += " <select name=\"interest\" lay-filter=\"interest\" id=\"exam-selected\"> ";
                      for (var i in res.data.list) {
                          html += "<option value=" + "\"" + res.data.list[i].name + "\"" + ">" + res.data.list[i].name + "</option>";
                      }
                      html += "</select> ";
                      var oContent = $('#exam-file')
                      oContent.html(html);
                      oContent.data("data", res.data.list);
                      reloadFrom();
                  } else {
                      alert('提交失败');
                  }
              },
              error: function (err) {
                  alert('提交失败' + err);
              }
          })
      }

      // 添加学生
      function getStudentsListManager() {
          $.ajax({
              url: '../../../ChireInter/Students/Students_List.ashx',
              data: { status: "1" },
              type: 'post',
              dataType: 'json',
              success: function (res) {
                  if (res.errCode == 200) {
                      var html = "";

                      html += " <select name=\"interest\" lay-filter=\"interest\" id=\"student-selected\" > ";
                      for (var i in res.data.list) {
         
                          html += "<option value=" + "\"" + res.data.list[i].name + "\"" + ">" + res.data.list[i].name + "</option>";
                      }
                      html += "</select> ";
                      var oContent = $('#student-list')
               
                      oContent.html(html);
                      oContent.data("data", res.data.list);
          
                      reloadFrom();
                  } else {
                      alert('提交失败');
                  }
              },
              error: function (err) {
                  alert('提交失败' + err);
              }
          })
      }

      // 刷新表单
      function reloadFrom() {
          layui.use(['form'], function () {
              var form = layui.form
              , layer = layui.layer;
          });

      }

  </script>   
 </body>
</html>